﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/BMP_Edit.master" AutoEventWireup="true"
    CodeFile="Edit.aspx.cs" Inherits="Pages_TRole_Edit" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript">

        var treeULID = "treeUL";
        var modelName = "TFunctionInfo";
        var checkedArray = new Array();
        var isLoading = false;

        $(function () {
            InitCheckArray();
            $('#' + treeULID).tree({
                checkbox: true,
                url: vRoot + 'Services/Handler.ashx?Type=' + modelName + '&PGID=0',
                height: 400,
                cascadeCheck: true,
                onBeforeLoad: function (row, param) {
                    isLoading = true;
                    if (row) {
                        $(this).tree('options').url = vRoot + 'Services/Handler.ashx?Type=' + modelName + '&PGID=' + row.id;
                    } else {
                        $(this).tree('options').url = vRoot + 'Services/Handler.ashx?Type=' + modelName + '&PGID=0';
                    }
                },
                onClick: function (node) {
                    $(this).tree('toggle', node.target);
                },
                onLoadSuccess: function () {
                    isLoading = false;
                    InitChecked();
                },
                onCheck: function (node, checked) {
                    if (!isLoading)
                        OnNodeChecked(node, checked);
                },
                onLoadError: function (e) {
                    alert(e);
                }
            });

        });

        function InitChecked() {
            checkedArray.HashForEach(function (item) {
                var node = $('#' + treeULID).tree('find', item);
                if (node && !node.checked) {
                    isInitChecked = true;
                    $('#' + treeULID).tree('check', node.target);
                    isInitChecked = false;
                }
            });
        }

        function InitCheckArray() {
            var arr = $("#checkedIDs").val().split(',');
            for (i = 0; i < arr.length; i++) {
                checkedArray[arr[i]] = arr[i];
            }
        }

        function OnNodeChecked(node, cheked) {
            if (isInitChecked)
                return;
            var idarray = treeCheckIds.Trim(',').split(',');
            if (cheked) {
                for (var i = 0; i < idarray.length; i++) {
                    checkedArray[idarray[i]] = idarray[i];
                }

            }
            else {
                for (var i = 0; i < idarray.length; i++) {
                    delete checkedArray[idarray[i]];
                }
            }
            treeCheckIds = "";
        }

        //得到当前界面选择的全部节点
        function GetCheckedNodes() {
            var c = "";
            var p = "";
            $(".tree-checkbox1").parent().children('.tree-title').each(function () {
                c += $(this).parent().attr('node-id') + ",";
            });
            $(".tree-checkbox2").parent().children('.tree-title').each(function () {
                p += $(this).parent().attr('node-id') + ",";
            });
            var str = (c + p);
            str = str.Trim(',');
            return str;
        }

        //将当前选择的界面，与历史节点进行叠加，得到最终权限。OnEditDetailSubmit
        function OnSubmitExtend() {
            var result = GetCheckedNodes().split(',');
            for (var i = 0; i < result.length; i++) {
                checkedArray[result[i]] = result[i];
            }
            var data = checkedArray.KeyToString().Trim(',');
            $("#checkedIDs").val(data);
            return true;
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentPlaceHolder" runat="Server">
    <asp:HiddenField ID="checkedIDs" runat="server" ClientIDMode="Static" />
    <div id="tab1">
        <table class="editTable" cellpadding="0" cellspacing="0">
            <tr>
                <th>
                    名称：
                </th>
                <td colspan="3">
                    <input id="TRoleInfo_Name" des="名称" emp="true" type="text" runat="server" />
                </td>
            </tr>
            <tr>
                <th>
                    权限设置
                </th>
                <td valign="top" colspan="3">
                    <ul id="treeUL">
                    </ul>
                </td>
            </tr>
        </table>
    </div>
    <div id="tab2">
        <table class="editTable" cellpadding="0" cellspacing="0">
        </table>
    </div>
</asp:Content>
